<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%
    String baseUrl = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath() + "/";
%>

<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<!DOCTYPE html>
<html>
<head>
    <base href="<%=baseUrl%>">
    <meta charset="utf-8">
    <title>会议室预约系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link href="/layui/css/layui.css" rel="stylesheet">
</head>
<body>
<div class="layui-layout layui-layout-admin">
    <div class="layui-header">
        <div class="layui-logo layui-hide-xs layui-bg-black">会议室预约系统</div>
        <!-- 头部区域（可配合layui 已有的水平导航） -->
        <ul class="layui-nav layui-layout-left">
            <!-- 移动端显示 -->
            <li class="layui-nav-item layui-show-xs-inline-block layui-hide-sm" lay-header-event="menuLeft">
                <i class="layui-icon layui-icon-spread-left"></i>
            </li>
            <c:forEach items="${applicationScope.loginUsers}" var="user">
                <li class="layui-nav-item layui-hide-xs"><a href="javascript:;">${user.name}</a></li>
            </c:forEach>

        </ul>
        <ul class="layui-nav layui-layout-right">
            <li class="layui-nav-item layui-hide layui-show-sm-inline-block">
                <a href="javascript:;">
                    <img src="upload?head=${sessionScope.user.head}" class="layui-nav-img">
                    ${sessionScope.user.name}
                </a>
                <dl class="layui-nav-child">
                    <dd><a href="javascript:;" class="edit"><i class="layui-icon layui-icon-edit"></i>修改信息</a></dd>
                    <dd><a href="javascript:;" class="resetPwd"><i class="layui-icon layui-icon-key"></i>修改密码</a>
                    </dd>
                    <dd><a href="user?action=logout"><i class="layui-icon layui-icon-logout"></i>退出登录</a></dd>
                </dl>
            </li>
            <li class="layui-nav-item" lay-header-event="menuRight" lay-unselect>
                <a href="javascript:;">
                    <i class="layui-icon layui-icon-more-vertical"></i>
                </a>
            </li>
        </ul>
    </div>
    <div class="layui-side layui-bg-black">
        <div class="layui-side-scroll">
            <!-- 左侧导航区域（可配合layui已有的垂直导航） -->
            <ul class="layui-nav layui-nav-tree" lay-filter="test">
                <li class="layui-nav-item layui-nav-itemed">
                    <a class="" href="javascript:;">预约管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-url="boardroom/list.jsp">会议室管理</a></dd>
                        <dd><a href="javascript:;" data-url="booking/list.jsp">预约会议室</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">员工管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-url="user/list.jsp">员工列表</a></dd>
                    </dl>
                </li>
                <li class="layui-nav-item">
                    <a href="javascript:;">部门管理</a>
                    <dl class="layui-nav-child">
                        <dd><a href="javascript:;" data-url="dept/list.jsp">部门列表</a></dd>
                    </dl>
                </li>
            </ul>
        </div>
    </div>
    <div class="layui-body">
        <!-- 内容主体区域 -->
        <div style="padding: 15px; height: 100%">
            <iframe id="frame" style="width: 100%; height: 100%; border-width: 0px"></iframe>
        </div>
    </div>
</div>

<script src="layui/layui.js"></script>
<script>
    //JS
    layui.use(['element', 'layer', 'util' , 'form'], function () {
        var element = layui.element;
        var layer = layui.layer;
        var util = layui.util;
        var form = layui.form;//引用layui的form组件
        var $ = layui.$;//就是jQuery

        //修改信息
        $('.edit').click(function () {
            layer.open({
                title:'修改信息',
                area:['800px' , '500px'],
                type:2,//iframe 子窗口
                content:'user/modify.jsp',//子窗口的URL
            });
        })
        //修改密码
        $('.resetPwd').click(function () {
        // 在此处输入 layer 的任意代码
            layer.open({
                type: 1, // page 层类型
                area: ['500px', '300px'],
                title: '修改密码',
                content:
                    '<div style="padding: 15px;">\
                      <form action="user?action=resetPwd" method="post">\
                        <div class="layui-form-item">\
                          <label class="layui-form-label">旧密码</label>\
                          <div class="layui-input-inline">\
                            <input class="layui-input" type="password" name="oldPwd" placeholder="请输入旧密码">\
                          </div>\
                        </div>\
                        <div class="layui-form-item">\
                          <label class="layui-form-label">新密码</label>\
                          <div class="layui-input-inline">\
                            <input class="layui-input" type="password" name="newPwd" placeholder="请输入新密码">\
                          </div>\
                        </div>\
                         <div class="layui-form-item">\
                          <label class="layui-form-label">确认密码</label>\
                          <div class="layui-input-inline">\
                            <input class="layui-input" type="password" name="rePwd" placeholder="请确认密码">\
                          </div>\
                        </div>\
                         <div class="layui-form-item">\
                          <div class="layui-input-block">\
                            <button class="layui-btn" lay-submit lay-filter="resetPwd">修改</button>\
                          </div>\
                        </div>\
                      </form>\
                    </div>'
            });
        })

        //表单的提交操作
        form.on('submit(resetPwd)' , function (data){
            //手动获取表单数据
            var oldPwd = $('[name="oldPwd"]').val();
            var newPwd = $('[name="newPwd"]').val();
            var rePwd = $('[name="rePwd"]').val();
            //ajax 发送修改密码的请求
            $.ajax({
                url:'user?action=resetPwd',//请求路径
                data:{oldPwd, newPwd, rePwd},//要传递参数
                type:'post',//http的请求方式
                dataType:'json',//返回数据类型
                success:function (result){//成功的回调 result服务器返回的数据
                    if (result.code == 0){
                        //成功
                        layer.msg("修改成功",{icon: 6}, function (index){
                            //跳转到登录页面
                            window.location.href = 'user/login.jsp';
                        });
                    }else {
                        //失败
                        layer.msg(result.msg , {icon: 5})
                    }
                },
                error:function (){
                    layer.msg('请求失败',{icon: 5});
                }
            });

            //阻止表单的自动提交
            return false;
        });

        //左侧的菜单事件
        $('.layui-nav-tree dd a').click(function (){
            var url = $(this).attr('data-url');
            if (url){
                //打开
                $('#frame').attr('src',url);
            }else {
                layer.msg("无效的url");
            }
        })
    });
</script>
</body>
</html>
